package com.wy.miniapp;

/**
 * @描述
 * @创建人 wangyue
 * @创建时间2020/5/616:16
 */

import cn.binarywang.wx.miniapp.api.WxMaService;
import cn.binarywang.wx.miniapp.api.impl.WxMaServiceImpl;
import cn.binarywang.wx.miniapp.config.impl.WxMaDefaultConfigImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class WxMaConfiguration {

    @Autowired(required = false)
    private MiniAppProperties miniAppProperties;

    private static WxMaService wxMaService = null;

    @Bean
    public Object services(){
        WxMaDefaultConfigImpl config = new WxMaDefaultConfigImpl();
        config.setAppid(miniAppProperties.getAppid());
        config.setSecret(miniAppProperties.getSecret());
        config.setToken(miniAppProperties.getToken());
        config.setAesKey(miniAppProperties.getAesKey());

        wxMaService = new WxMaServiceImpl();
        wxMaService.setWxMaConfig(config);

        return Boolean.TRUE;
    }

    public static WxMaService getWxMaService(){
        return wxMaService;
    }
}